Parser.spec.js ➔ ... ➔ ???   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 6
Bugs 0 Features 0
Metric Value
c 6
b 0
f 0
nc 1
dl 0
loc 7
rs 9.4285
cc 1
nop 0
1
'use strict';
2
3
import * as fs from 'fs';
4
import * as path from 'path';
5
import { assert } from 'chai';
6
import Parser from '../../src/Parser';
7
import { Input, Lexer } from '../../src/Lexer';
8
import helloWorldAst from '../Data/hello_world.ast.json';
9
import pkg from '../../package.json';
10
11
/** @test {Parser} */
12
describe(`${pkg.name}/Parser/Parser`, () => {
13
  /** @test {Parser#constructor} */
14
  describe('#constructor', () => {
15
    it('Create a new instance of type Parser', () => {
16
      const input = new Input('+Hello World'),
17
            lexer = new Lexer(input),
18
            parser = new Parser(lexer);
19
20
      assert.instanceOf(parser, Parser);
21
    });
22
  });
23
24
  /** @test {Parser#parse} */
25
  describe('#parse', () => {
26
    it('Parse program', () => {
27
      const sourceCode = fs.readFileSync(path.join(__dirname, '..', 'Data', 'hello_world.bot'), {
28
              encoding : 'utf8',
29
              flag     : 'r'
30
            }),
31
            input = new Input(sourceCode),
32
            lexer = new Lexer(input),
33
            parser = new Parser(lexer),
34
            code = parser.parse();
35
36
      assert.isObject(code);
37
      assert.deepEqual(code, helloWorldAst);
38
    });
39
  });
40
41
  /** @test {Parser#replaceStringSubstitution} */
42
  describe('#replaceStringSubstitution', () => {
43
    it('Should replace the string substitution character in a given string', () => {
44
      assert.notInclude(Parser.replaceStringSubstitution('I $ you because you are so $!'), '$');
45
    });
46
  });
47
48
  /** @test {Parser#replaceWildcard} */
49
  describe('#replaceWildcard', () => {
50
    it('Should replace the wildcard substitution character in a given string', () => {
51
      assert.notInclude(Parser.replaceWildcard('What do you think about * and *?'), '*');
52
    });
53
  });
54
});
55